package cn.edu.hunau.java.week02.day04.com;

import java.util.Comparator;

public class User implements Comparable<User> {
    private int id;
    private String name;

    static class SortByStringLength implements Comparator<User>{
        @Override
        public int compare(User o1,User o2){
            return o1.getName().length()-o2.getName().length();
        }
    }

    public User() {
    }

    public User(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public int compareTo(User o){
        return this.id-o.id;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }
}
